Skip to content

Replace deprecated asyncio and typing APIs#2

Open
cgoudie wants to merge 1 commit intomainfrom
chore/remove-deprecated-apis
Open

Replace deprecated asyncio and typing APIs#2
cgoudie wants to merge 1 commit intomainfrom
chore/remove-deprecated-apis

Conversation

@cgoudie
Copy link
Copy Markdown
Contributor

@cgoudie cgoudie commented Apr 10, 2026

Summary

  • asyncio.Runner replaces asyncio.new_event_loop() + asyncio.set_event_loop() + loop.run_until_complete() + loop.close() in the scanner thread. set_event_loop() is deprecated since Python 3.10 and scheduled for removal in 3.14. asyncio.Runner (introduced in 3.11) is the recommended replacement — it manages loop lifecycle internally and properly registers the loop for the thread, which dbus-fast relies on for signal dispatch.

  • Built-in generic types replace typing.Dict, typing.Set, typing.Tuple, and typing.Optional. These typing aliases have been deprecated since Python 3.9 (generics) and 3.10 (union syntax). The from typing import ... line is removed entirely.

  • BaseException catch replaces Exception in the scanner thread so that asyncio.CancelledError (a BaseException subclass since Python 3.8) doesn't silently kill the thread.

Verified on Cerbo GX

Deployed and tested on Cerbo GX (Python 3.12.12, BlueZ 5.72, kernel 6.12.23-venus-5).

The system was experiencing unrelated periodic reboots (load averages 8–10) during testing, so the service was tested across 5 consecutive clean starts. Each run operated without any application errors until the system rebooted.

Run Start Duration Outcome
1 02:55 ~21 min Clean — system reboot
2 03:28 ~19 min Clean — system reboot
3 04:00 ~16 min Clean — system reboot
4 04:18 ~21 min Clean — system reboot
5 04:53 ~18 min Clean — system reboot

Total: ~95 minutes cumulative clean runtime, zero application errors.

Verified across all runs:

  • Passive scanners start on both hci0 and hci1
  • Advertisement callbacks are received and routed to registered clients (Orion TR, Shyion, SeeLevel)
  • Bootstrap processes cached BlueZ devices on startup
  • Same PID throughout each run (no unexpected restarts)
  • D-Bus service responds correctly (Connected=1, State=256)
  • No errors, exceptions, or thread deaths in any run

Test plan

  • Verify passive scanning still starts and delivers advertisement callbacks
  • Verify no regressions in advertisement routing to registered clients
  • Verify clean shutdown via svc -d / SIGTERM (scanner thread joins, no stale BlueZ monitors) — not tested due to system instability

- asyncio.new_event_loop() + set_event_loop() + run_until_complete()
  replaced with asyncio.Runner (deprecated since 3.12, removal planned
  for 3.14)
- typing.Dict/Set/Tuple/Optional replaced with built-in generics and
  union syntax (deprecated since 3.9/3.10)
- Catch BaseException instead of Exception in scanner thread so
  CancelledError doesn't silently kill it

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant